﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using ControleRepresentante.Logic.Models;
using Telerik.Web.Mvc.UI.Fluent;

namespace WebSite.ViewModels.EditViewModels.EditGridViewModels
{
    public abstract class EnderecoEditGridViewModel<TItem> : EditGridViewModel<TItem>
        where TItem : EnderecoViewModel
    {
        protected EnderecoEditGridViewModel(HtmlHelper htmlHelper, string controllerName, IEnumerable<TItem> models, string routeKey = null, string gridName = "Endereco")
            : base(htmlHelper, gridName, controllerName, models, routeKey)
        {
        }

        protected override void Columns(GridColumnFactory<TItem> configurator)
        {
            configurator.Bound(endereco => endereco.Tipo);
            configurator.Bound(endereco => endereco.Rua);
            configurator.Bound(endereco => endereco.Numero);
            configurator.Bound(endereco => endereco.Complemento);
            configurator.Bound(endereco => endereco.Bairro);
            configurator.Bound(endereco => endereco.CEP);
            configurator.Bound(endereco => endereco.Cidade);
            configurator.Bound(endereco => endereco.Estado);
            configurator.Bound(endereco => endereco.Observacao);
            configurator.Bound(endereco => endereco.Principal);
        }
    }

    public class EnderecoEditGridViewModel : EnderecoEditGridViewModel<EnderecoViewModel>
    {
        public EnderecoEditGridViewModel(HtmlHelper htmlHelper, string controllerName, DetailsHolder detailsHolder)
            : base(htmlHelper, controllerName, detailsHolder.Enderecos.Select(x => new EnderecoViewModel(x)))
        {
        }
    }
}